<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Han">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/try6.gitee.io/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/try6.gitee.io/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/try6.gitee.io/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/try6.gitee.io/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/try6.gitee.io/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/try6.gitee.io/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/try6.gitee.io/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="场景：移动端列表显示，数据庞大。后台数据有分页字段 需求：需要快速显示页面，需要显示当前页数，需要跨页跳转Pc端可以使用分页按钮，但是移动端屏幕小，分页按钮不方便操作。">
<meta property="og:type" content="article">
<meta property="og:title" content="移动端触摸分页方案">
<meta property="og:url" content="http://try66.gitee.io/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/index.html">
<meta property="og:site_name" content="Hello JS">
<meta property="og:description" content="场景：移动端列表显示，数据庞大。后台数据有分页字段 需求：需要快速显示页面，需要显示当前页数，需要跨页跳转Pc端可以使用分页按钮，但是移动端屏幕小，分页按钮不方便操作。">
<meta property="og:locale" content="zh-Han">
<meta property="og:image" content="http://note.youdao.com/yws/public/resource/e7c63b13f28ec75fa92b3926d72f20e1/xmlnote/9CBCE96B770E4EB7A646E67885C91EE8/11350">
<meta property="og:updated_time" content="2018-08-16T12:38:18.112Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="移动端触摸分页方案">
<meta name="twitter:description" content="场景：移动端列表显示，数据庞大。后台数据有分页字段 需求：需要快速显示页面，需要显示当前页数，需要跨页跳转Pc端可以使用分页按钮，但是移动端屏幕小，分页按钮不方便操作。">
<meta name="twitter:image" content="http://note.youdao.com/yws/public/resource/e7c63b13f28ec75fa92b3926d72f20e1/xmlnote/9CBCE96B770E4EB7A646E67885C91EE8/11350">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/try6.gitee.io/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://try66.gitee.io/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/"/>





  <title>移动端触摸分页方案 | Hello JS</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cc7e3057efb482b0f56c29d2716384da";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Han">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/try6.gitee.io/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Hello JS</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">所有的安排都是最好的</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/try6.gitee.io/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/try6.gitee.io/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://try66.gitee.io/try6.gitee.io/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Try_Luies">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/try6.gitee.io/images/pic.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hello JS">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">移动端触摸分页方案</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-09-28T06:47:46+08:00">
                2017-09-28
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2017/09/28/2017-09-28移动端触摸分页方案-1/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/" class="leancloud_visitors" data-flag-title="移动端触摸分页方案">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">Visitors&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <ul>
<li>场景：移动端列表显示，数据庞大。后台数据有分页字段</li>
<li>需求：需要快速显示页面，需要显示当前页数，需要跨页跳转<br>Pc端可以使用分页按钮，但是移动端屏幕小，分页按钮不方便操作。</li>
</ul>
<a id="more"></a>
<h3 id="思路分析"><a href="#思路分析" class="headerlink" title="思路分析"></a>思路分析</h3><ol>
<li>思路1：下拉刷新实现分页加载<br>可以使用iscroll插件进行下拉刷新，符合用户使用习惯。但是无法进行跨页跳转，也无法显示当前页码</li>
<li>思路2：使用搜索功能，查找想要的数据。<br>参考了淘宝对商品的筛选功能，用户可以选择筛选条件进行查询。实用性强，但实现步骤较为繁琐</li>
<li>思路3：使用滑块快速跳转页码<br>这种方式最符合需求，查找了资料，可以使用UIsilder组件，但是样式不太美观，与产品界面风格不符。</li>
</ol>
<p>经过讨论和初步实践，决定选取第3种方案，但不采取slider组件，参考某些阅读器的分页样式，也可以参考微信通讯录的滑动实现。</p>
<h3 id="类似效果图"><a href="#类似效果图" class="headerlink" title="类似效果图"></a>类似效果图</h3><p><img src="http://note.youdao.com/yws/public/resource/e7c63b13f28ec75fa92b3926d72f20e1/xmlnote/9CBCE96B770E4EB7A646E67885C91EE8/11350" alt=""> </p>
<h3 id="具体实操"><a href="#具体实操" class="headerlink" title="具体实操"></a>具体实操</h3><h5 id="html和css部分"><a href="#html和css部分" class="headerlink" title="html和css部分"></a>html和css部分</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">//页码部分</span><br><span class="line"></span><br><span class="line">&lt;div id=&quot;sliderPage&quot;&gt;</span><br><span class="line"></span><br><span class="line">    &lt;div id=&quot;wrap&quot;  &gt;&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">//放大显示页码标签</span><br><span class="line"></span><br><span class="line">&lt;div class=&quot;largePage&quot; &gt;</span><br><span class="line"></span><br><span class="line">    &lt;span&gt;1&lt;/span&gt;</span><br><span class="line"></span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure>
<p>设置样式让页面如图显示</p>
<h5 id="js部分"><a href="#js部分" class="headerlink" title="js部分"></a>js部分</h5><p>滑动跳转，滑动在于Js部分的动作交互，跳转在于数据接口的调用。</p>
<p>1.滑动<br>这部分主要使用了touch系列事件，在页面dom上添加touch事件。我这里直接加在了html节点上。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;div id=&quot;sliderPage&quot; ontouchend=&quot;touchEnd()&quot; ontouchmove=&quot;move()&quot;&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>
<p> |</p>
<p></p>
<p>重点代码</p>
<h4 id="根据数据创建页码"><a href="#根据数据创建页码" class="headerlink" title="根据数据创建页码"></a>根据数据创建页码</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">function createPage()&#123;</span><br><span class="line"></span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    //pageCount为页码数。</span><br><span class="line"></span><br><span class="line">    //total为数据总数，这里每页显示10条。</span><br><span class="line"></span><br><span class="line">    var pageCount =  parseInt((total+ (10 - 1)) / 10);   </span><br><span class="line"></span><br><span class="line">    var str;</span><br><span class="line"></span><br><span class="line">    for(let i = i;i &lt;= pageCount+1;i++)&#123;</span><br><span class="line"></span><br><span class="line">        str +=&apos;&lt;a ontouchstrat=start(this) &gt;&apos;+i+&apos;&lt;/a&gt;&apos;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $(&quot;wrap&quot;).html(str);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#### touchstart事件获取当前页码,并将页码显示在largepage下的标签中</span><br></pre></td></tr></table></figure>
<p>function start(n){</p>
<pre><code>var text= $(n).text;

$(.largePage span).text(text);

 $(&quot;.largePage span&quot;).css(&quot;opacity&quot;,&quot;1&quot;)
</code></pre><p>}</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#### touchmove滑动事件</span><br></pre></td></tr></table></figure>
<p>function move(){</p>
<pre><code>//滑动切换页码

//将页码显示在

//根据start对象的宽高进行切换

start(document.elementFromPoint(event.changedTouches[0].clientX, event.changedTouches[0].clientY))
</code></pre><p>}</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#### touchend滑动结束,页码提示隐藏，跳转页面</span><br></pre></td></tr></table></figure>
<p>function touchEnd(){</p>
<pre><code> $(&quot;.largePage&quot;).animate({

     opacity:0

},500)

//页面跳转操作
</code></pre><p>}</p>
<h3 id="现象分析"><a href="#现象分析" class="headerlink" title="现象分析"></a>现象分析</h3><p>功能逻辑不复杂，但是涉及到了touch系列事件的操作。页面如果存在一些click事件或者其他的touch事件，就会出现各种问题。</p>
<h4 id="对click事件的影响。"><a href="#对click事件的影响。" class="headerlink" title="对click事件的影响。"></a>对click事件的影响。</h4><p>touch事件结束后会触发节点的click事件</p>
<p>在移动端，手指点击一个元素，会经过：<code>touchstart --&gt; touchmove -&gt; touchend --&gt;click</code></p>
<p>事件流本身会持续进行下去。</p>
<p><code>touchstart</code> 触发之后，<code>click</code>事件还被触发了，<code>onclick</code>属性也被触发了。</p>
<p>使用<code>preventDefault()</code>方法可以阻止click事件被触发。</p>
<p><code>event.preventDefault()</code>表示取消默认事件，比如可以禁止touchmove事件触发时页面滚动。一般情况都要加上，否则会出现很多怪异现象</p>
<h4 id="事件冒泡"><a href="#事件冒泡" class="headerlink" title="事件冒泡"></a>事件冒泡</h4><p>页面document也有touchmove和end事件，用于显示和隐藏页码条。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">//触发touchmove事件显示页码条</span><br><span class="line"></span><br><span class="line">document.addEventListener(&quot;touchmove&quot;,function()&#123;</span><br><span class="line"></span><br><span class="line">    $(&quot;#sliderPage&quot;).animate(&#123;</span><br><span class="line"></span><br><span class="line">        opacity:1</span><br><span class="line"></span><br><span class="line">    &#125;,500)</span><br><span class="line"></span><br><span class="line">&#125;,false);</span><br><span class="line"></span><br><span class="line">//触发touchend事件隐藏页码条</span><br><span class="line"></span><br><span class="line">document.addEventListener(&quot;touchend&quot;,function()&#123;</span><br><span class="line"></span><br><span class="line">    $(&quot;#sliderPage&quot;).animate(&#123;</span><br><span class="line"></span><br><span class="line">        opacity:0</span><br><span class="line"></span><br><span class="line">    &#125;,2000)</span><br><span class="line"></span><br><span class="line">&#125;,false)</span><br></pre></td></tr></table></figure>
<p>这么写在sliderPage上滑动的时候也会触发这两个事件，造成sliderPage不稳定时隐时现。所以要关闭touch事件的冒泡行为</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">//在所有的Touch事件中加上这一句</span><br><span class="line"></span><br><span class="line">event.stopPropagation();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">不过我采取了另外一种方式。使用监听滚动条变化来显示和隐藏页码条，也就没有这个问题了.</span><br></pre></td></tr></table></figure>
<p>//页面滚动时，显示页码条</p>
<p>$(window).on(‘scroll’, function() {</p>
<pre><code>$(&quot;#sliderPage&quot;).animate({

    opacity:1

},500);

//设置延时，隐藏页码条

setInterval(function(){

    $(&quot;#sliderPage&quot;).animate({

        opacity:0

    },2000);

},3000)
</code></pre><p>})</p>
<h4 id="touch事件拓展"><a href="#touch事件拓展" class="headerlink" title="touch事件拓展"></a>touch事件拓展</h4><p>touch事件都会冒泡，也都可以取消。虽然这些触摸事件没有在DOM规范中定义，但是它们却是以兼容DOM的方式实现的。所以，每个触摸事件的event对象都提供了在鼠标实践中常见的属性：</p>
<ul>
<li><p>bubbles(起泡事件的类型)</p>
</li>
<li><p>cancelable(是否用 preventDefault() 方法可以取消与事件关联的默认动作)</p>
</li>
<li><p>clientX(返回当事件被触发时，鼠标指针的水平坐标)</p>
</li>
<li><p>clientY(返回当事件触发时，鼠标指针的垂直坐标)</p>
</li>
<li><p>screenX(当某个事件被触发时，鼠标指针的水平坐标)</p>
</li>
<li><p>screenY(返回当某个事件被触发时，鼠标指针的垂直坐标)</p>
</li>
</ul>
<p>touch对象代表一个触点，可以通过event.touches[0]获取<br>除了常见的DOM属性，触摸事件还包含下面三个用于跟踪触摸的属性</p>
<ul>
<li>touches：表示当前跟踪的触摸操作的touch对象的数组。</li>
<li>targetTouches：特定于事件目标的Touch对象的数组。</li>
<li>changeTouches：表示自上次触摸以来发生了什么改变的Touch对象的数组。</li>
</ul>
<p>每个Touch对象包含的属性如下。</p>
<ul>
<li>identifier：标识触摸的唯一ID。</li>
<li><p>clientX：触摸目标在<code>视口</code>中的x坐标。</p>
</li>
<li><p>pageX：触摸目标在<code>页面</code>中的x坐标</p>
</li>
<li><p>screenX：触摸目标在<code>屏幕</code>中的x坐标。</p>
</li>
<li>target：触摸的DOM节点目标。</li>
<li><p>ex：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">function load ()&#123;  </span><br><span class="line"></span><br><span class="line">    document.addEventListener(&apos;touchstart&apos;,touch, false);  </span><br><span class="line"></span><br><span class="line">    document.addEventListener(&apos;touchmove&apos;,touch, false);  </span><br><span class="line"></span><br><span class="line">    document.addEventListener(&apos;touchend&apos;,touch, false);  </span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">function touch (event)&#123;  </span><br><span class="line"></span><br><span class="line">    var event = event || window.event;  </span><br><span class="line"></span><br><span class="line">    var oInp = document.getElementById(&quot;inp&quot;); </span><br><span class="line"></span><br><span class="line">    switch(event.type)&#123;  </span><br><span class="line"></span><br><span class="line">        case &quot;touchstart&quot;:  </span><br><span class="line"></span><br><span class="line">            oInp.innerHTML = &quot;Touch started (&quot; + event.touches[0].clientX + &quot;,&quot; + event.touches[0].clientY + &quot;)&quot;;  </span><br><span class="line"></span><br><span class="line">            break;  </span><br><span class="line"></span><br><span class="line">        case &quot;touchend&quot;:  </span><br><span class="line"></span><br><span class="line">            oInp.innerHTML = &quot;&lt;br&gt;Touch end (&quot; + event.changedTouches[0].clientX + &quot;,&quot; + event.changedTouches[0].clientY + &quot;)&quot;;  </span><br><span class="line"></span><br><span class="line">            break;  </span><br><span class="line"></span><br><span class="line">        case &quot;touchmove&quot;:  </span><br><span class="line"></span><br><span class="line">            event.preventDefault();  </span><br><span class="line"></span><br><span class="line">            oInp.innerHTML = &quot;&lt;br&gt;Touch moved (&quot; + event.touches[0].clientX + &quot;,&quot; + event.touches[0].clientY + &quot;)&quot;;  </span><br><span class="line"></span><br><span class="line">            break;  </span><br><span class="line"></span><br><span class="line">    &#125;  </span><br><span class="line"></span><br><span class="line">&#125;    </span><br><span class="line"></span><br><span class="line">window.addEventListener(&apos;load&apos;,load, false);</span><br></pre></td></tr></table></figure>
</li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Try_Luies WeChat Pay"/>
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Try_Luies Alipay"/>
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/try6.gitee.io/2017/12/07/2017-12-07京东大导航——预判用户行为（一）/" rel="prev" title="京东大导航——预判用户行为（一）">
                京东大导航——预判用户行为（一） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/try6.gitee.io/images/pic.jpg"
                alt="Try_Luies" />
            
              <p class="site-author-name" itemprop="name">Try_Luies</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/try6.gitee.io/archives/">
              
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/try6" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-GitHub"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/7a6944daafc3" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-globe"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="www.baidu.com" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-微博"></i>微博</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#思路分析"><span class="nav-number">1.</span> <span class="nav-text">思路分析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#类似效果图"><span class="nav-number">2.</span> <span class="nav-text">类似效果图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#具体实操"><span class="nav-number">3.</span> <span class="nav-text">具体实操</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#html和css部分"><span class="nav-number">3.0.1.</span> <span class="nav-text">html和css部分</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#js部分"><span class="nav-number">3.0.2.</span> <span class="nav-text">js部分</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#根据数据创建页码"><span class="nav-number">3.1.</span> <span class="nav-text">根据数据创建页码</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#现象分析"><span class="nav-number">4.</span> <span class="nav-text">现象分析</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#对click事件的影响。"><span class="nav-number">4.1.</span> <span class="nav-text">对click事件的影响。</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#事件冒泡"><span class="nav-number">4.2.</span> <span class="nav-text">事件冒泡</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#touch事件拓展"><span class="nav-number">4.3.</span> <span class="nav-text">touch事件拓展</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Try_Luies</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/try6.gitee.io/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/try6.gitee.io/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/try6.gitee.io/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/try6.gitee.io/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/try6.gitee.io/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/try6.gitee.io/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://try.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://try66.gitee.io/try6.gitee.io/2017/09/28/2017-09-28移动端触摸分页方案-1/';
          this.page.identifier = '2017/09/28/2017-09-28移动端触摸分页方案-1/';
          this.page.title = '移动端触摸分页方案';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://try.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("", "");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
